<!DOCTYPE html>
<html>
<head>
    <include file="Public:header"/>
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <p>
                        <button type="button" id="add" class="btn btn-white btn-sm btn-outline"><i
                                class="fa fa-plus-square-o"></i>&nbsp;新增
                        </button>
                        <button type="button" id="edit" class="btn btn-white btn-sm btn-outline"><i
                                class="fa fa-edit"></i>&nbsp;修改
                        </button>
                        <button type="button" id="editSeq" class="btn btn-white btn-sm btn-outline"><i
                                class="fa fa-sort-numeric-asc"></i>&nbsp;修改排序
                        </button>
                        <button type="button" id="del" class="btn btn-white btn-sm btn-outline"><i
                                class="fa fa-trash-o"></i>&nbsp;删除
                        </button>
                    </p>
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<!-- 全局js -->
<include file="Public:foot"/>
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        //初始化
        $.jgrid.defaults.styleUI = 'Bootstrap';
        $("#table_list").jqGrid({
            url: '__URL__/getAllData',
            datatype: "json",
            height: 580,
            autowidth: true,
            shrinkToFit: true,
            rowNum: 15,
            rowList: [10, 15, 30, 50],
            colNames: ['ID', '省', '市', '区', '学校', '排序', '操作'],
            colModel: [{name: 'id', index: 'id'},
                {name: 'name', index: 'name'},
                {name: 'province', index: 'province'},
                {name: 'city', index: 'realname'},
                {name: 'area', index: 'area'},
                {name: 'seq', index: 'seq'},
                {
                    name: 'status', index: 'status', formatter: function (cellvalue, options, rowObject) {
                        content = '<i class="fa fa-th-large"></i><a class="J_menuItem" href="/home/Admin/School/schoolAreas?id='+ rowObject.id +'" data-index="14"> 区域</a>';
                        content += '&nbsp;&nbsp;<i class="fa fa-home"></i><a class="J_menuItem" href="/home/Admin/School/schoolFloor?id='+ rowObject.id +'" data-index="14"> 大楼</a>';
                    return content;
                }
                },
            ],
            pager: "#pager_list",
            viewrecords: true,
            hidegrid: false,
            sortname: "seq",
            sortorder: "asc",
        });
        // 设置按钮
        $("#table_list").jqGrid('navGrid', '#pager_list', {
            edit: false,
            add: false,
            del: false,
            search: false
        }, {
            height: 200,
            reloadAfterSubmit: true
        });
        // 添加适配响应
        $(window).bind('resize', function () {
            var width = $('.jqGrid_wrapper').width();
            $('#table_list').setGridWidth(width);
        });

        //增
        $("#add").click(function () {
            layerDialog("新增", '__URL__/add', "90%", "360px", true);
        })

        //改
        $("#edit").click(function () {
            var id = $("#table_list").jqGrid('getGridParam', 'selrow');
            if (id != null) {
                layerDialog("修改", '__URL__/edit?id=' + id, "90%", "50%", true);
            } else {
                layer.msg("您没有选取数据！");
            }
        })

        //修改排序
        $("#editSeq").click(function () {
            layerDialog("修改排序", '__URL__/editSeq', "90%", "90%", true);
        })

        //删
        $("#del").click(function () {
            var id = $("#table_list").jqGrid('getGridParam', 'selrow');
            if (id != null) {
                layer.confirm('确定执行？', function (index) {
                    $.ajax({
                        url: "__URL__/logicDel",
                        type: "post",
                        data: {'id': id},
                        success: function (json) {
                            var data = eval("(" + json + ")");
                            if (data.status == 1) {
                                layer.msg(data.info);
                                $('#table_list').trigger("reloadGrid");
                            } else {
                                layer.msg(data.info);
                            }
                        }
                    })
                    layer.close(index);
                });
            } else {
                layer.msg("您没有选取数据！");
            }
        })

        //学校区域
        $("#schoolAreas").click(function () {
            var id = $("#table_list").jqGrid('getGridParam', 'selrow');
            if (id != null) {
                layerDialog("学校区域", '__URL__/schoolAreas?id=' + id, "90%", "90%", true);
            } else {
                layer.msg("您没有选取数据！");
            }
        })
    });
</script>
</html>